package com.feifan.web.controller.oa;

import com.feifan.common.annotation.Log;
import com.feifan.common.core.controller.BaseController;
import com.feifan.common.core.domain.AjaxResult;
import com.feifan.common.core.page.TableDataInfo;
import com.feifan.common.enums.BusinessType;
import com.feifan.common.utils.poi.ExcelUtil;
import com.feifan.oa.domain.FlowCategoryInfo;
import com.feifan.oa.service.IFlowCategoryInfoService;
import com.feifan.oa.service.IFlowCategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程类别明细Controller
 * @author 非凡
 * @date 2020-06-30
 */
@Controller
@RequestMapping("/oa/info")
public class FlowCategoryInfoController extends BaseController {
    private String prefix = "oa/flow/info";

    @Autowired
    private IFlowCategoryInfoService flowCategoryInfoService;

    @Autowired
    private IFlowCategoryService flowCategoryService;

    @RequiresPermissions("oa:info:view")
    @GetMapping()
    public String info(ModelMap mmap) {
        mmap.put("flowCategoryList", flowCategoryService.selectFlowCategoryList(null));
        return prefix + "/info";
    }

    /**
     * 查询流程类别明细列表
     */
    //@RequiresPermissions("oa:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FlowCategoryInfo flowCategoryInfo) {
        startPage();
        List<FlowCategoryInfo> list = flowCategoryInfoService.selectFlowCategoryInfoList(flowCategoryInfo);
        return getDataTable(list);
    }

    /**
     * 导出流程类别明细列表
     */
    @RequiresPermissions("oa:info:export")
    @Log(title = "流程类别明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FlowCategoryInfo flowCategoryInfo) {
        List<FlowCategoryInfo> list = flowCategoryInfoService.selectFlowCategoryInfoList(flowCategoryInfo);
        ExcelUtil<FlowCategoryInfo> util = new ExcelUtil<FlowCategoryInfo>(FlowCategoryInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 新增流程类别明细
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        mmap.put("flowCategoryList", flowCategoryService.selectFlowCategoryList(null));
        return prefix + "/add";
    }

    /**
     * 新增保存流程类别明细
     */
    @RequiresPermissions("oa:info:add")
    @Log(title = "流程类别明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FlowCategoryInfo flowCategoryInfo) {
        return toAjax(flowCategoryInfoService.insertFlowCategoryInfo(flowCategoryInfo));
    }

    /**
     * 修改流程类别明细
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        mmap.put("flowCategoryList", flowCategoryService.selectFlowCategoryList(null));
        mmap.put("flowCategoryInfo", flowCategoryInfoService.selectFlowCategoryInfoById(id));
        return prefix + "/edit";
    }

    /**
     * 修改保存流程类别明细
     */
    @RequiresPermissions("oa:info:edit")
    @Log(title = "流程类别明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FlowCategoryInfo flowCategoryInfo) {
        return toAjax(flowCategoryInfoService.updateFlowCategoryInfo(flowCategoryInfo));
    }

    /**
     * 删除流程类别明细
     */
    @RequiresPermissions("oa:info:remove")
    @Log(title = "流程类别明细", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(flowCategoryInfoService.deleteFlowCategoryInfoByIds(ids));
    }
}
